/*================================================================
*   Copyright (C) 2019 Guangzhou Firefly Ltd. All rights reserved.
*   
*   文件名称：getComStrLen.c
*   创 建 者：luhuadong
*   创建日期：2019年10月11日
*   描    述：计算两个字符串的最大公共字串的长度，字符不区分大小写
*
================================================================*/


#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <time.h>

#define DEBUG 0

int getCommonStrLength(char* pFirstStr, char* pSecondStr)
{
	assert(pFirstStr && pSecondStr);

	int i, j, k;
	int max = 0;

	/* 将两个字符串转换为小写 */
	for(i=0; pFirstStr[i] != '\0'; i++) {
	
		pFirstStr[i] = tolower(pFirstStr[i]);
	}

	for(i=0; pSecondStr[i] != '\0'; i++) {
	
		pSecondStr[i] = tolower(pSecondStr[i]);
	}

#if(DEBUG)
	printf("getCommonStrLength(%s, %s)\n", pFirstStr, pSecondStr);
#endif

	for(i=0; pFirstStr[i] != '\0'; i++) {
	
		for(j=0; pSecondStr[j] != '\0'; j++) {
		
			if(pFirstStr[i] == pSecondStr[j]) {

				for(k=1; pFirstStr[i+k] != '\0' && pSecondStr[j+k] != '\0'; k++) {

					if(pFirstStr[i+k] != pSecondStr[j+k]) {
						break;
					}
				}
			
				if(k > max) 
					max = k;

#if(DEBUG)
				printf("match: %c, i=%d, j=%d, len=%d, max=%d\n", pFirstStr[i], i, j, k, max);
#endif
			}
		}
	}

	return max;
}

int main(void)
{
	char firstStr[128] = {0};   /* 存放第一个字符串 */
	char secondStr[128] = {0};  /* 存放第二个字符串 */
	int  length = 0;
	clock_t begin, end;
	unsigned int run_time;

	scanf("%s %s", firstStr, secondStr);

	begin = clock();
	length = getCommonStrLength(firstStr, secondStr);
	end = clock();

	/* 统计算法执行时间 */
	run_time = (end - begin) * 1000.0 / CLOCKS_PER_SEC * 1000;

	printf("max=%d, time=%uus\n", length, run_time);
	
	return 0;
}

